package top.glike.ssl.auto.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import top.glike.ssl.auto.domain.SslCloudProvider;
import top.glike.ssl.auto.service.ISslCloudProviderService;
import top.glike.ssl.common.annotation.Log;
import top.glike.ssl.common.core.controller.BaseController;
import top.glike.ssl.common.core.domain.AjaxResult;
import top.glike.ssl.common.core.page.TableDataInfo;
import top.glike.ssl.common.enums.BusinessType;
import top.glike.ssl.common.utils.poi.ExcelUtil;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 厂商配置Controller
 *
 * @author Sophia
 * @date 2025-10-12
 */
@RestController
@RequestMapping("/auto/provider")
public class SslCloudProviderController extends BaseController {

    @Autowired
    private ISslCloudProviderService sslCloudProviderService;

    /**
     * 查询厂商配置列表
     */
    @PreAuthorize("@ss.hasPermi('auto:provider:list')")
    @GetMapping("/list")
    public TableDataInfo list(SslCloudProvider sslCloudProvider) {
        startPage();
        List<SslCloudProvider> list = sslCloudProviderService.selectSslCloudProviderList(sslCloudProvider);
        return getDataTable(list);
    }

    /**
     * 导出厂商配置列表
     */
    @PreAuthorize("@ss.hasPermi('auto:provider:export')")
    @Log(title = "厂商配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SslCloudProvider sslCloudProvider) {
        List<SslCloudProvider> list = sslCloudProviderService.selectSslCloudProviderList(sslCloudProvider);
        ExcelUtil<SslCloudProvider> util = new ExcelUtil<SslCloudProvider>(SslCloudProvider.class);
        util.exportExcel(response, list, "厂商配置数据");
    }

    /**
     * 获取厂商配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('auto:provider:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sslCloudProviderService.selectSslCloudProviderById(id));
    }

    /**
     * 新增厂商配置
     */
    @PreAuthorize("@ss.hasPermi('auto:provider:add')")
    @Log(title = "厂商配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SslCloudProvider sslCloudProvider) {
        return toAjax(sslCloudProviderService.insertSslCloudProvider(sslCloudProvider));
    }

    /**
     * 修改厂商配置
     */
    @PreAuthorize("@ss.hasPermi('auto:provider:edit')")
    @Log(title = "厂商配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SslCloudProvider sslCloudProvider) {
        return toAjax(sslCloudProviderService.updateSslCloudProvider(sslCloudProvider));
    }

    /**
     * 删除厂商配置
     */
    @PreAuthorize("@ss.hasPermi('auto:provider:remove')")
    @Log(title = "厂商配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sslCloudProviderService.deleteSslCloudProviderByIds(ids));
    }
}
